const babel = require('babel-core');
const myPlugin = require('./babel_my_plugin');

const example = 'const foo = 1; console.log(foo);'
console.log('原始code: ', example)
// 转换步骤: babel-core 向外暴露出 babel.transform 接口,可通过插件介入节点操作
const res = babel.transform(example, {
  plugins: [ myPlugin ]
});
console.log('转换code: ', res.code)